﻿using Architecture.Repository;
using Architeture.Domain;
using Architeture.Domain.DTO;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC.ZhuBoLin.Application.Command.RoleCommand.Mach;
using RBAC.ZhuBoLin.Dtos;

namespace RBAC.ZhuBoLin.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class MachController : ControllerBase
    {
        protected readonly IMediator mediator;

        public MachController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 深加工添加
        /// </summary>
        /// <param name="cd"></param>
        /// <returns></returns>
        
        [HttpPost]
        public async Task<ApiResult<int>> MachUpd(MachiningCreateCommand cd)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await mediator.Send(cd);
            }
            catch (Exception ex)
            {
                result.Code = 0;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 深加工显示
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        
        [HttpGet]
        public async Task<ApiResult<machiningInfo>> GetMachinfo([FromQuery]MachiningSelectCommand sd)
        {
            ApiResult<machiningInfo> result = new ApiResult<machiningInfo>();
            try
            {
                result.Data = await mediator.Send(sd);
            }
            catch (Exception ex)
            {
                result.Code = 0;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

    }
}
